//
//  serviceConnectToWifi.m
//  upnpxdemo
//
//  Created by 赵帅 on 13-9-1.
//  Copyright (c) 2013年 wiimu.inc. All rights reserved.
//

#import "serviceConnectToWifi.h"

@implementation serviceConnectToWifi
#pragma mark Initialization & Deallocation

-(id)initWithDelegate:(id <serviceConnectToWifiDelegate>) aDelegate
{
	self = [super init];
	if (self)
	{
		self.m_serviceHandler = aDelegate;
	}
    
	return self;
}



#pragma mark -
#pragma mark Configure the request
-(NSURL*)targetURL
{
    NSString * ipStr = [m_dicSendData objectForKey:@"baseurl"];
    NSString *urlStr = [NSString stringWithFormat:@"%@/httpapi.asp",ipStr];
	NSURL *theUrl = [[NSURL alloc] initWithString:urlStr];
	
	return theUrl;
}

-(void)configureRequest
{
	[super configureRequest];
    
    [m_request setRequestMethod:@"POST"];
    
    NSString * ssid = [m_dicSendData objectForKey:@"ssid"];
    NSString * auth = [m_dicSendData objectForKey:@"auth"];
    NSString * password = [m_dicSendData objectForKey:@"password"];
    NSString * channel = [m_dicSendData objectForKey:@"channel"];
    NSString * encry = [m_dicSendData objectForKey:@"encrypt"];
    
    if(password == nil || [password length] == 0)
    {
        password = @"NONE";
    }
    
    [m_request setPostValue:@"wlanConnect1Ap" forKey:@"command"];
    [m_request setPostValue:ssid forKey:@"ssid"];
    [m_request setPostValue:password forKey:@"pwd"];
    [m_request setPostValue:auth forKey:@"auth"];
    [m_request setPostValue:encry forKey:@"encry"];
    [m_request setPostValue:channel forKey:@"channel"];
    //encry channel
}

#pragma mark -
#pragma mark Parse the response
-(void)parseResponseData:(NSData *)data
{
	[super parseResponseData:data];
    
}

#pragma mark -
#pragma mark Pass Data To UI
-(void)passDataOut
{
	[super passDataOut];
	
	if (nil != self.m_serviceHandler
		&& [self.m_serviceHandler respondsToSelector:@selector(serviceConnectToWifiCallBack:)])
	{
        [self.m_serviceHandler performSelectorOnMainThread:@selector(serviceConnectToWifiCallBack:) withObject:m_dicReceiveData waitUntilDone:YES];
	}
}
@end
